#pragma strict
//上下左右旋转.
var rotX:float;
var rotY:float;
//上下旋转的最大范围.
var minRotY:float = -1;
var maxRotY:float = 1;

var rotSpeed:float = 4; // 单位 弧度.
var moveSpeed:float = 4;

function Start () {

}

function Update () {
	rotX += Input.GetAxis("Mouse X") * rotSpeed * Time.deltaTime;
	rotY += Input.GetAxis("Mouse Y") * rotSpeed * Time.deltaTime;
	rotY = Mathf.Clamp(rotY,minRotY,maxRotY);
	
	transform.localRotation = Quaternion.AngleAxis(rotX * Mathf.Rad2Deg,Vector3.up);
	transform.localRotation *= Quaternion.AngleAxis(rotY * Mathf.Rad2Deg,Vector3.left);
	
	//使用世界坐标.
	// transform.position += transform.forward * moveSpeed * Time.deltaTime * Input.GetAxis("Vertical");
	// transform.position += transform.right * moveSpeed * Time.deltaTime * Input.GetAxis("Horizontal");
	
	//使用局部坐标.
	var moveDir:Vector3 = Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical")) * moveSpeed * Time.deltaTime;
	moveDir = transform.localRotation * moveDir;
	transform.localPosition += moveDir;
}